package com.example.aaaaa.ftn1;


import java.util.List;

import com.example.aaaaa.R;

import com.example.aaaaa.Activity.MainActivity;
import com.example.aaaaa.ViewModel.*;


import android.content.Intent;
import android.os.Bundle;

import android.util.Log;
import android.view.View;

import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class Activity1 extends MainActivity {
    
	
	private TextView tv1;
	private Button btn1;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_activity1);
		Log.d("Activity1","On creating....");
	}
/*
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_activity1, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			// This ID represents the Home or Up button. In the case of this
			// activity, the Up button is shown. Use NavUtils to allow users
			// to navigate up one level in the application structure. For
			// more details, see the Navigation pattern on Android Design:
			//
			// http://developer.android.com/design/patterns/navigation.html#up-vs-back
			//
			NavUtils.navigateUpFromSameTask(this);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
*/
	@Override
	protected ViewModel initModel() {
		Log.d("activity1","in initModel....");
		ViewModelX vmX=new ViewModelX();
		vmX.setAge(10);
		Log.d("activity1","1111111111111111111....");
		//vmX.setDisplayTxt("I love you!");
		Log.d("activity1","will return from initModel");
		return vmX;
	}

	@Override
	protected void initControlsAndRegEvent() {
		this.tv1=(TextView) findViewById(R.id.vt1);
		this.btn1=(Button )findViewById(R.id.btn1);
		btn1.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
			   
				//((ViewModelX)getVm()).setAge(10);
				
				toActitity(Activity1.this, Aoivtity2.class);
				
				
				/*
				Bundle bdl=vmx.writeToBundle();
				
				Intent intent=new Intent(Activity1.this,Aoivtity2.class);
				
				intent.putExtras(bdl);
				
				startActivity(intent);*/
				
			
			}
		});
	}


	@Override
	protected void upDateView(ViewModel Vm) {
		
		ViewModelX vm1=(ViewModelX)Vm;
		//tv1.setText(vm1.getDisplayTxt());
		String dspTxt=Integer.toString(vm1.getAge());
		tv1.setText(dspTxt);
		
	}
	@Override
	protected void processViewModelErrorMsg(List<ModelErrorInfo> errsOfVM,
			String errMsg) {
		
		Toast ast=Toast.makeText(this, errMsg, Toast.LENGTH_LONG);
		
		ast.show();
		
	}

}
